//////////////////////////////////////////////////////////////////////////
//
// GAM203
// GameObject base class
// GameObject.cpp
// 
// Scott Taylor
// Qantm College
//
//////////////////////////////////////////////////////////////////////////

#include "GameObject.h"
#include "Renderer.h"
#include "Octree.h"
#include "TerrainManager.h"

GameObject::GameObject()
: m_pos(0, 0, 0)
, m_yawPitchRoll(0, 0, 0)
, m_pMeshFileName(NULL)
{
}

GameObject::~GameObject()
{
}

D3DXVECTOR3 GameObject::GetCameraAttachPos() const
{
	return m_pos;
}

D3DXVECTOR3 GameObject::GetCameraTrackPos() const
{
	return m_pos;
}
bool GameObject::CheckCollision(D3DXVECTOR3 a_min, D3DXVECTOR3 a_max)
{
	//	a_min += a_pos;
	//	a_max += a_pos;
	D3DXVECTOR3 minBounds = m_minBounds + m_pos;
	D3DXVECTOR3 maxBounds = m_maxBounds + m_pos;
	//Check to see if the drawable object overlaps the node at all
	if(a_max.x > minBounds.x)
	{
		//Inside left wall - Because of the way D3DXComputeBoundingBox() works,
		//the left side of the bounding box is a negative number, so add it, not subtract
		if(a_min.x < maxBounds.x)
		{
			//Inside top wall
			if(a_max.y > minBounds.y)
			{
				//Inside bottom wall - Because of the way D3DXComputeBoundingBox() works,
				//the bottom side of the bounding box is a negative number, so add it, not subtract
				if(a_min.y < maxBounds.y)
				{		
					//Inside back wall
					if(a_max.z > minBounds.z)
					{
						//Inside front wall - Because of the way D3DXComputeBoundingBox() works,
						//the front side of the bounding box is a negative number, so add it, not subtract
						if(a_min.z < maxBounds.z)							
						{
							//If it makes it here, it is overlapping the node, add it to this nodes object list
							return true;
						}
					}
				}
			}
		}
	}
	return false;
}
void GameObject::StartFire()
{
	//Iterate through renderers list of octree objects and call CheckCollision and each pElem
}
void GameObject::SetYPR(D3DXVECTOR3 a_ypr)
{
	m_yawPitchRoll = a_ypr;
}
void GameObject::MoveForward(float a_val, float a_dt)
{
	float directionx = sinf(GetYaw());
	float directionz = cosf(GetYaw());
	m_pos.x -= (directionx*a_val)*a_dt;
	m_pos.y = TerrainManager::GetInstance().GetTerrainHeight(m_pos.x, m_pos.z);
	m_pos.z -= (directionz*a_val)*a_dt;
}
void GameObject::MoveBackward(float a_val, float a_dt)
{
	float directionx = sinf(GetYaw());
	float directionz = cosf(GetYaw());
	m_pos.x += (directionx*a_val)*a_dt;
	m_pos.y = TerrainManager::GetInstance().GetTerrainHeight(m_pos.x, m_pos.z);
	m_pos.z += (directionz*a_val)*a_dt;
}
void GameObject::TurnLeft(float a_val, float a_dt)
{
	SetYaw((-a_val*a_dt)+GetYaw());
}
void GameObject::TurnRight(float a_val, float a_dt)
{
	SetYaw((a_val*a_dt)+GetYaw());
}
void GameObject::StrafeLeft(float a_val, float a_dt)
{

}
void GameObject::StrafeRight(float a_val, float a_dt)
{

}
